import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/provider.dart';

import '../provider/person_info.dart';

class Person extends StatefulWidget {
  const Person({super.key});

  @override
  State<StatefulWidget> createState() => _Person();
}

class _Person extends State<Person> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 30),
      height: 150,
      width: double.infinity,
      decoration: BoxDecoration(
        border: Border.all(
          color: const Color.fromARGB(255, 107, 102, 102),
          width: 2,
        ),
      ),
      child: const Row(
        children: [HeadButton(), Myinfo()],
      ),
    );
  }
}

class HeadButton extends StatefulWidget {
  const HeadButton({super.key});

  @override
  State<StatefulWidget> createState() => _HeadButton();
}

class _HeadButton extends State<HeadButton> {
  void openGallery() async {
    final ImagePicker picker = ImagePicker();
    var image = await picker.pickImage(source: ImageSource.gallery);
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
        height: 150,
        width: 150,
        child: IconButton(
            icon: const CircleAvatar(
              backgroundImage: AssetImage('image/headPortrait.png'),
              radius: 50,
            ),
            onPressed: openGallery));
  }
}

class Myinfo extends StatefulWidget {
  const Myinfo({super.key});

  @override
  State<StatefulWidget> createState() => _Myinfo();
}

class _Myinfo extends State<Myinfo> {
  @override
  Widget build(BuildContext context) {
    return Container(
        margin: EdgeInsets.only(left: MediaQuery.of(context).size.width * 0.05),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Consumer<PersonInfo>(builder: (ctx, person, child) {
              return Text(
                person.name,
                style: const TextStyle(fontSize: 18),
              );
            }),
            const SizedBox(height: 20),
            Consumer<PersonInfo>(builder: (ctx, person, child) {
              return Text("所属联盟: ${person.alliance}");
            })
          ],
        ));
  }
}
